<?php
/**
 * Created by PhpStorm.
 * User: ysfl
 * Date: 2015/11/29
 * Time: 20:50
 * 流水帐
 */

//名字空间
namespace app\admin\controllers;

use modules\admin\InventoryModule;
use modules\admin\WastebookModule;

class   Wastebook extends Admin
{
    //首页方法
    function index()
    {
        $this->display($this->data);
    }

    //添加流水帐方法
    function  addWastebook()
    {

        //注册模块
        $ADMIN = new WastebookModule();

        //注册商品库模块，懒得重写了......
        $TYPE = new InventoryModule();

        //获取所有用户名字
        $this->data['user'] = $ADMIN->W_User_List();

        //获取往来企业客户名字
        $this->data['gname'] = $ADMIN->G_Name();

        //获取商品名字
        $this->data['iname'] = $ADMIN->W_Item();

        //获取店铺名字
        $this->data['sname'] = $ADMIN->W_Shops();

        //获取商品分类
        $this->data['shopsname'] = $TYPE->Shops_Type();

        //提交检测
        if ($this->is_post()) {

            //发送数据给Waste_bookModule模块里的addWaste_book函数处理并取返回值赋予add_w_e
            $this->data['add_w_e'] = $ADMIN->addWastebook($_POST);
        }

        //调用视图并发送数据给视图
        $this->display($this->data);
    }

    //查看流水帐方法
    function  queryWastebook()
    {
        //注册模块
        $ADMIN = new WastebookModule();

        //未付查询
        $this->data['wf'] = $ADMIN->C_Money(array('mprice' => '未付','start' => 0));

        //营业额查询
        $this->data['price'] = $ADMIN->C_Money(array('mprice' => array('or',array('现金','已结款')),'start' => 1,'time' => array('like',date('Y-m-%'))));

        //白露本月营业额查询
        $this->data['bailu'] = $ADMIN->C_Money(array('start' => array('=','1') ,'addr' =>'白露店','time' => array('like',date('Y-m%'))));

        //文化广场本月营业额查询
        $this->data['wh'] = $ADMIN->C_Money(array('start' => array('=','1') ,'addr' =>'文化广场店','time' => array('like',date('Y-m%'))));

        //白露本月营业额查询
        $this->data['wfbailu'] = $ADMIN->C_Money(array('start' => 0 ,'addr' =>'白露店','mprice' => '未付','time' => array('like',date('Y-m%'))));

        //文化广场本月营业额查询
        $this->data['wfwh'] = $ADMIN->C_Money(array('start' => 0 ,'addr' =>'文化广场店','mprice' => '未付','time' => array('like',date('Y-m%'))));

        //白露当日营业额查询
        $this->data['nbailu'] = $ADMIN->C_Money(array('start' => array('!=','2') ,'addr' =>'白露店','time' => array('like',date('Y-m-d%'))));

        //文化广场当日营业额查询
        $this->data['nwh'] = $ADMIN->C_Money(array('start' => array('!=','2'),'addr' =>'文化广场店','time' => array('like',date('Y-m-d%'))));

        //本月目标查询
        $this->data['m'] = $ADMIN->M_Target(array('month' => date('m')));

        //流水列表查询
        $this->data['query'] = $ADMIN->Query_Wastebook_List(array('start' => '0'));

        //调用视图并发送数据给视图
        $this->display($this->data);
    }

    //查询价格
    function upprice()
    {
        //注册模块
        $ADMIN = new WastebookModule();

        if ($this -> is_post()){

            $s = $ADMIN->Q_Price(
                array(
                    'iname' => $_POST['name'],
                    'user' => $_POST['user']
                )
            );

            return $s;
        }
    }

    //入账
    function wastebookset()
    {
        //注册模块
        $ADMIN = new WastebookModule();

        if ($this -> is_post()){

            $data = array(
                    'id' => $_POST['id'],
                    'start' => $_POST['start'],
                    'mprice' => $_POST['mprice'],
                    'mtime' => $_POST['mtime']
                    );

            return $ADMIN->W_Set($data);
        }
    }

    //查询
    function W_Gname()
    {
        $arr = new WastebookModule();

        $list = $arr->G_Name();

        foreach($list as $k){
            return $k['name'];
        }
    }

    //已入账列表
    function Wastebook_List()
    {
        //注册模块
        $ADMIN = new WastebookModule();

        //未付查询
        $this->data['wf'] = $ADMIN->C_Money(array('mprice' => '未付','start' => 0,'time' => array('like','2016-06%')));

        //营业额查询
        $this->data['price'] = $ADMIN->C_Money(array('mprice' => array('or',array('现金','已结款')),'start' => 1,'time' => array('like',date('Y-06-%'))));

        //白露本月营业额查询
        $this->data['bailu'] = $ADMIN->C_Money(array('start' => array('=','1') ,'addr' =>'白露店','time' => array('like',date('Y-06%'))));

        //文化广场本月营业额查询
        $this->data['wh'] = $ADMIN->C_Money(array('start' => array('=','1') ,'addr' =>'文化广场店','time' => array('like',date('Y-06%'))));

        //白露本月营业额查询
        $this->data['wfbailu'] = $ADMIN->C_Money(array('start' => 1 ,'addr' =>'白露店','mprice' => '未付','time' => array('like',date('Y-06%'))));

        //文化广场本月营业额查询
        $this->data['wfwh'] = $ADMIN->C_Money(array('start' => 1 ,'addr' =>'文化广场店','mprice' => '未付','time' => array('like',date('Y-06%'))));

        //上月目标查询
        $this->data['m'] = $ADMIN->M_Target(array('month' => '06'));

        //流水列表查询
        $this->data['query'] = $ADMIN->Query_Wastebook_List(array('start' => '1','time' => array('like','2016-06%')));

        //调用视图并发送数据给视图
        $this->display($this->data);
    }

    //支出页面
    function Expenditure()
    {
        //注册模块
        $ADMIN = new WastebookModule();

        //获取处理完的数据
        $this->data['list'] = $ADMIN->W_Expenditure();

        if ($this -> is_post()){

            switch ($_POST['start']){
                case 'add':
                    //添加支出项目
                    $data = array(
                        'time' => $_POST['time'],
                        'text' => $_POST['text'],
                        'price' => $_POST['price'],
                        'name' => $_POST['name']
                    );

                    return $ADMIN->W_Expenditure_Add($data);
                    break;
                case 'set':
                    //更改状态
                    $data = array(
                        'id' => $_POST['id'],
                        'v' => $_POST['v'],
                        'c' => $_POST['c']
                    );

                    return $ADMIN->W_Expenditure_Set($data);
                    break;
            }

        }

        $this->display($this->data);
    }
}